package org.zfes.snowier.cloud.zbss.widget.act.route.service.stu;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.util.ZBeanUtil;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.auth.shiro.util.SecurityUtil;
import org.zfes.snowier.cloud.zbss.widget.act.dto.ActSubjectQuesAnswerCreateDto;
import org.zfes.snowier.cloud.zbss.widget.act.model.ActQuestion;
import org.zfes.snowier.cloud.zbss.widget.act.model.ActSubjectQuesAnswer;
import org.zfes.snowier.cloud.zbss.widget.act.service.IActSubjectQuesAnswerService;
@Controller("org.zfes.snowier.cloud.zbss.widget.act.route.service.stu.actSubjectQuesAnswerController") 
@RequestMapping("/active/service/stu/actSubjectQuesAnswer")
public class ActSubjectQuesAnswerController extends BaseController {

	
	@Autowired
	private IActSubjectQuesAnswerService actSubjectQuesAnswerService;
	
    @RequestMapping(value="/createAnswer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createAnswer(ActSubjectQuesAnswerCreateDto answerDto){
    	
    	ZBeanUtil.validateBean(answerDto);
    	
    	ActSubjectQuesAnswer answer=answerDto.toAnswer()
    			.setAnswerUserId(SecurityUtil.getUserId().get())
    			.setAnswerUser(SecurityUtil.getUserName().get());
    	
		actSubjectQuesAnswerService.createActSubjectProcessAnswer(answer);
		
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/loadOpenAnswer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object loadOpenAnswer(Long id){
    	Optional<ActQuestion> actQuestion=actSubjectQuesAnswerService.loadOpenAnswer( id) ;
    	return  ajaxQuery("actQuestion",actQuestion);
    }
	


}